﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace WeiMiao
{
    public class UI : MonoBehaviour
    {
        //控制是否不销毁
        public bool Destruction;

        //设置、游戏内控件，通关
        public GameObject control, checkpoint,pass;

        //获取当前场景
        int Scene;
        //获取音乐控件
        GameObject overallmusic;

        // Start is called before the first frame update
        void Start()
        {
            //销毁的相关代码
            if (Destruction)
            {
                DontDestroyOnLoad(gameObject);
            }
            overallmusic = GameObject.Find("OverallMusic");
        }

        //游戏退出
        public void exit()
        {
            Application.Quit();
        }

        /// <summary>
        /// 场景跳转
        /// </summary>
        /// <param name="number">跳转的场景</param>
        public void JumpScene(int number)
        {
            //跳转的场景
            SceneManager.LoadScene(number);
            //通关
            Scene = SceneManager.GetActiveScene().buildIndex;
            //判断控件显示
            if (Scene != 0)
            {
                GameObject ui = GameObject.Find("OverallUI");
                if (ui != null)
                {
                    ui.GetComponent<UI>().pass.SetActive(false);
                    if (Scene <= 2)
                    {
                        ui.GetComponent<UI>().checkpoint.SetActive(true);
                    }
                    else
                    {
                        ui.GetComponent<UI>().checkpoint.SetActive(false);
                    }
                }
            }
        }

        /// <summary>
        /// 判断设置界面
        /// </summary>
        public void Control()
        {
            if (control.activeInHierarchy)
            {
                control.SetActive(false);
            }
            else
            {
                control.SetActive(true);
            }
        }

        /// <summary>
        /// 通关
        /// </summary>
        public void Pass()
        {
            GetComponent<UI>().pass.SetActive(true);
            //GetComponent<UI>().overallmusic.GetComponent<Music>().Sound(2);
        }

        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }
}